package com.J.Plane;


/**
 * Vector implementation
 *
 */
public class Vector3 {
	public float x;
	public float y;
	public float z;

	public static final Vector3 ZERO_VECTOR = new Vector3();
	public static final Vector3 UNIT_SCALE_VECTOR = new Vector3(1.0f, 1.0f,
			1.0f);

	public Vector3() {
		x = y = z = 0.0f;
	}

	public Vector3(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public Vector3(final Vector3 rhs) {
		this(rhs.x, rhs.y, rhs.z);
	}

	public void set(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public void add(float x, float y, float z) {
		this.x += x;
		this.y += y;
		this.z += z;
	}
	public void add(final Vector3 v) {
		add(v.x,v.y,v.z);
	}

	public Vector3 clone() {
		return new Vector3(x, y, z);
	}

	public void copyFrom(Vector3 rhs) {
		x = rhs.x;
		y = rhs.y;
		z = rhs.z;
	}
	
	public float length() {
		return (float)Math.sqrt(x*x + y*y + z*z);
	}
	
	public Vector3 normalize() {
		float len = this.length();
		x/=len;
		y/=len;
		z/=len;
		return this;
	}
	
	
	/**
	 * Check equality
	 * @param x
	 * @param d
	 * @param z
	 * @return
	 */
	public boolean isSame(float x, double d, float z) {
		return this.x == x &&
			this.y == d &&
			this.z == z;
	}
	
	public static void multiply(final Vector3 a, final Vector3 b, Vector3 out) {
		out.x = a.x * b.x;
		out.y = a.y * b.y;
		out.z = a.z * b.z;		
	}
	
		
	public static void subtract(final Vector3 a, final Vector3 b, Vector3 out) {
		float outx = a.x - b.x;
		float outy = a.y - b.y;
		float outz = a.z - b.z;
		
		out.x = outx;
		out.y = outy;
		out.z = outz;
	}
	
	
	/**
	 * Cross product
	 * @param a
	 * @param b
	 * @param out
	 */
	public static void cross(final Vector3 a, final Vector3 b, Vector3 out) {
		float outx = a.y*b.z - a.z*b.y;
		float outy = a.z*b.x - a.x*b.z;
		float outz = a.x*b.y - a.y*b.x;
		
		out.x = outx;
		out.y = outy;
		out.z = outz;
	}
	
	
}
